package com.yuerlive.rainbow.widget;

import android.app.AlertDialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.yuerlive.rainbow.R;
import com.yuerlive.rainbow.utils.DeviceUtils;


/**
 * Created by admin on 2016/9/13.
 */
public class InputDialog extends AlertDialog {
    /***
     *
     * @param context
     * @param contentView
     *            配置文件
     *            集合
     */
    public InputDialog(final Context context, View contentView) {
        super(context, R.style.InputDialog);
        if (!isShowing()) {
            show();
        }
        int width = DeviceUtils.deviceWidth(context);
        Window window = getWindow();
        setCancelable(true);
        window.setWindowAnimations(R.style.inputDialogAnim); // 设置窗口弹出动画
        setCanceledOnTouchOutside(true);
        WindowManager.LayoutParams params =
                window.getAttributes();
        window.setGravity(Gravity.BOTTOM);
        window.setBackgroundDrawableResource(android.R.color.transparent); // 设置对话框背景为透明
        params.width = width;
        window.setAttributes(params);
        window.setContentView(contentView);
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    }

    @Override
    public void show() {
        isShowing = true;
        super.show();
    }

    @Override
    public void hide() {
        isShowing = false;
        super.hide();
    }

    @Override
    public void dismiss() {
        isShowing = false;
        super.dismiss();
    }

    @Override
    public boolean isShowing() {
        return isShowing;
    }

    private boolean isShowing;
}
